import QtQuick 2.0
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import "../components"

Window {

    id: root
    title: "样本信息"
    modality: Qt.WindowModal
    flags: Qt.Window | Qt.WindowTitleHint |Qt.WindowSystemMenuHint | Qt.WindowCloseButtonHint


    minimumHeight: 600*dp
    maximumHeight: 600*dp
    minimumWidth: 1000*dp
    maximumWidth: 1000*dp


    property var letters: ["A", "B", "C", "D", "E", "F", "G", "H"]
    property var scales: [0.1, 0.1, 0.2, 0.18, 0.18, 0.24]
    property int displayMode: 0     // 0: 全部孔位  1: 已设置孔位

    function setData(data){
        listModel.clear()
        for(let i = 0; i < data.length; i ++){
            listModel.append({
                                 "Item1": i+1,              // 序号
                                 "Item2": letters[Math.floor(i/12)]+(i%12+1).toString(),       // 孔位
                                 "Item3": data[i]["SampleName"],       // 样本名称
                                 "Item4": data[i]["SampleType"],       // 样本类型
                                 "Item5": data[i]["SampleConc"].toString(),       // 浓度
                                 "Item6": (data[i]["FAM"].toString()==="1" ? "FAM  " : "") +  // 通道
                                          (data[i]["VIC"].toString()==="1" ? "VIC  " : "") +
                                          (data[i]["ROX"].toString()==="1" ? "ROX  " : "") +
                                          (data[i]["CY5"].toString()==="1" ? "CY5  "  : ""),
                             })
        }
    }

    CustomComboBox{
        x: 40*dp; y: 20*dp
        model: ["全部孔位", "已设置孔位"]
        onCurrentIndex: {
            displayMode = index
        }
    }

    // 表头
    Rectangle{
        y: 80*dp
        x: 40*dp
        width: root.width - 70*dp
        height: 40*dp
        color: "#E6E6E6"
        Rectangle{
            height: parent.height - 2; width: parent.width
            y: 1; x: 0
        }
        Row{
            anchors.fill: parent
            Item{
                height: parent.height
                width: parent.width * scales[0]
                Text{
                    text: "序号"
                    anchors.centerIn: parent
                    color: "#888888"
                    font.pixelSize: config.fontsize
                }
            }Item{
                height: parent.height
                width: parent.width * scales[1]
                Text{
                    text: "孔位"
                    anchors.centerIn: parent
                    color: "#888888"
                    font.pixelSize: config.fontsize
                }
            }Item{
                height: parent.height
                width: parent.width  * scales[2]
                Text{
                    text: "样本名称"
                    anchors.centerIn: parent
                    color: "#888888"
                    font.pixelSize: config.fontsize
                }
            }Item{
                height: parent.height
                width: parent.width * scales[3]
                Text{
                    text: "样本类型"
                    anchors.centerIn: parent
                    color: "#888888"
                    font.pixelSize: config.fontsize
                }
            }Item{
                height: parent.height
                width: parent.width * scales[4]
                Text{
                    text: "浓度"
                    anchors.centerIn: parent
                    color: "#888888"
                    font.pixelSize: config.fontsize
                }
            }Item{
                height: parent.height
                width: parent.width * scales[5]
                Text{
                    text: "通道     "
                    anchors.centerIn: parent
                    color: "#888888"
                    font.pixelSize: config.fontsize
                }
            }
        }
        z: 1
    }

    ListView{
        id: listView
        width: root.width - 80*dp
        height: root.height - 130*dp
        x: 40*dp; y: 120*dp
        delegate: delegateLine
        model: listModel
        clip: true
    }
    ListModel{
        id: listModel
    }
    Component{
        id: delegateLine
        Rectangle{
            property string sampleName: Item3
            property string sampleType: Item4
            property string sampleChannel: Item6
            clip: true
            height: {
                if(displayMode===0 || (this.sampleName!=="" || this.sampleType!=="" || this.sampleChannel!=="")){
                    return 40*dp
                }else{
                    return 0
                }
            }
            width: root.width - 80*dp
            Rectangle{
                height: 1;  width: root.width - 80*dp
                color: "#E6E6E6"
                y: parent.height - 1
            }
            Row{
                anchors.fill: parent
                Item{
                    height: parent.height
                    width: parent.width * scales[0]
                    Text{
                        text: Item1
                        anchors.centerIn: parent
                        font.pixelSize: config.fontsize
                    }
                }Item{
                    height: parent.height
                    width: parent.width * scales[1]
                    Text{
                        text: Item2
                        anchors.centerIn: parent
                        font.pixelSize: config.fontsize
                    }
                }Item{
                    height: parent.height
                    width: parent.width * scales[2]
                    Text{
                        text: Item3
                        anchors.centerIn: parent
                        font.pixelSize: config.fontsize
                    }
                }Item{
                    height: parent.height
                    width: parent.width * scales[3]
                    Text{
                        text: Item4
                        anchors.centerIn: parent
                        font.pixelSize: config.fontsize
                    }
                }Item{
                    height: parent.height
                    width: parent.width * scales[4]
                    Text{
                        text: Item5
                        anchors.centerIn: parent
                        font.pixelSize: config.fontsize
                    }
                }Item{
                    height: parent.height
                    width: parent.width * scales[5]
                    Text{
                        text: Item6
                        anchors.centerIn: parent
                        font.pixelSize: config.fontsize
                    }
                }
            }
        }
    }


}
